/**
 * @properties={typeid:35,uuid:"80B7F605-A9DD-4C84-BD4D-C3BB66D47D57",variableType:4}
 */
var fSalir = 0;

/**
 * @properties={typeid:35,uuid:"07D38538-FFEA-42EF-83AE-2E4DF4F183E2"}
 */
var fUsuario = null;

/**
 * @properties={typeid:35,uuid:"30D7693B-1664-4B24-ACD0-686F76C5381E"}
 */
var fPass = null;

/**
 * Handle hide window.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"2FE7E8F4-311D-4152-BB89-5483803CC25D"}
 */
function onHide(event) {
	if (fSalir == 0)
		return false
	return true
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"32B082A0-1977-4AE1-8154-F2CD1861C5C1"}
 */
function entrar(event) {
	
	var usrUID = security.getUserUID( fUsuario)
	if (usrUID != null)
	{
		if (security.checkPassword(usrUID, fPass) == true)
		{
			var g = new Array('Usuario')
			if (security.login(fUsuario, usrUID, g) == false)
			{
				globals.gDialog('Error','Fallo en el login. Usuario incorrecto o permiso denegado','OK','CerrarForm')
			}
			else
			{// ENTRO
				var fs = databaseManager.getFoundSet('fwk_navigation_infocom','usuarios')
				fs.find()
				fs.usuario = fUsuario
				var cant = fs.search()
				if (cant == 1)
				{
					if (fs.hash_pass == utils.stringMD5HashBase64(fPass))
					{
						globals.gUserv = fs.userv_id
						globals.gUsuario = fs.usuario_id
						fSalir = 1
						databaseManager.addTableFilterParam('factura_electronica','campos_extra','id_userv','=',globals.gUserv,'EXTRA')
						globals.gParamsUsr(globals.gUserv)
						forms.menu.controller.show()
					}
					else
					{
						security.logout()
						globals.gDialog('Error','Contraseña distinta entre app server y tabla de usuarios','OK','CerrarForm')
					}
				}
				else
				{
					security.logout()
					globals.gDialog('Error','Usuario no esta en tabla de usuarios','OK','CerrarForm')
				}
			}
		}
		else
			globals.gDialog('Error','Contraseña Invalida','OK','CerrarForm')
	}
	else
		globals.gDialog('Error','Usuario no existe','OK','CerrarForm')


}
